package com.ruoyi.business.controller;

import java.util.List;

import com.ruoyi.business.domain.AuthBindingInfo;
import com.ruoyi.business.domain.vo.AuthBindingInfoReviewVO;
import com.ruoyi.business.domain.vo.CommonReviewVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.WxCompany;
import com.ruoyi.business.service.IWxCompanyService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 公司认证管理Controller
 * 
 * @author ruoyi
 * @date 2021-11-19
 */
@RestController
@RequestMapping("/business/wx_company")
public class WxCompanyController extends BaseController
{
    @Autowired
    private IWxCompanyService wxCompanyService;

    /**
     * 查询公司认证管理列表
     */
    @PreAuthorize("@ss.hasPermi('business:wx_company:list')")
    @GetMapping("/list")
    public TableDataInfo list(WxCompany wxCompany)
    {
        startPage();
        List<WxCompany> list = wxCompanyService.selectWxCompanyList(wxCompany);
        return getDataTable(list);
    }

    /**
     * 导出公司认证管理列表
     */
    @PreAuthorize("@ss.hasPermi('business:wx_company:export')")
    @Log(title = "公司认证管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(WxCompany wxCompany)
    {
        List<WxCompany> list = wxCompanyService.selectWxCompanyList(wxCompany);
        ExcelUtil<WxCompany> util = new ExcelUtil<WxCompany>(WxCompany.class);
        return util.exportExcel(list, "公司认证管理数据");
    }

    /**
     * 获取公司认证管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:wx_company:query')")
    @GetMapping(value = "/{companyId}")
    public AjaxResult getInfo(@PathVariable("companyId") Long companyId)
    {
        return AjaxResult.success(wxCompanyService.selectWxCompanyByCompanyId(companyId));
    }

    /**
     * 新增公司认证管理
     */
    @PreAuthorize("@ss.hasPermi('business:wx_company:add')")
    @Log(title = "公司认证管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WxCompany wxCompany)
    {
        return toAjax(wxCompanyService.insertWxCompany(wxCompany));
    }

    /**
     * 修改公司认证管理
     */
    @PreAuthorize("@ss.hasPermi('business:wx_company:edit')")
    @Log(title = "公司认证管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WxCompany wxCompany)
    {
        return toAjax(wxCompanyService.updateWxCompany(wxCompany));
    }

    /**
     * 删除公司认证管理
     */
    @PreAuthorize("@ss.hasPermi('business:wx_company:remove')")
    @Log(title = "公司认证管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{companyIds}")
    public AjaxResult remove(@PathVariable Long[] companyIds)
    {
        return toAjax(wxCompanyService.deleteWxCompanyByCompanyIds(companyIds));
    }

    /**
     * 申请公司认证
     */
    @Log(title = "申请业主认证", businessType = BusinessType.INSERT)
    @PostMapping("/apply")
    public AjaxResult apply(@RequestBody WxCompany wxCompany)
    {
        return toAjax(wxCompanyService.applyCompanyAuthInfo(wxCompany));
    }

    /**
     * 申请公司认证
     */
    @Log(title = "审批业主认证", businessType = BusinessType.INSERT)
    @PostMapping("/review")
    public AjaxResult review(@RequestBody CommonReviewVO commonReviewVO)
    {
        return toAjax(wxCompanyService.reviewCompanyAuthInfo(commonReviewVO));
    }

    @GetMapping(value = "/getByWxUserId/{wxUserId}")
    public AjaxResult getByWxUserId(@PathVariable("wxUserId") Long wxUserId)
    {
        return AjaxResult.success(wxCompanyService.selectWxCompanyByWxUserId(wxUserId));
    }
}
